package com.zlx.exchange.conversation.service.impl;

import cn.hutool.json.JSONUtil;
import cn.hutool.json.ObjectMapper;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.zlx.exchange.conversation.dao.MessageDao;
import com.zlx.exchange.conversation.service.ConversationService;
import com.zlx.exchange.domain.entity.Message;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.websocket.Session;
import java.util.Date;

@Service
public class ConversationServiceImpl implements ConversationService {
    @Autowired
    private MessageDao messageDao;

    /**
     * 存储信息
     * @param message
     * @param token
     */
    @Override
    public void sendMessage(String message, String token) {
        System.out.println("token"+token);
        Object userId = JWTUtil.parseToken(token).getPayload("userId");
        System.out.println("token"+userId);
        Message message1 = new Message();
        message1.setSenderId(Integer.parseInt(userId.toString()));
        message1.setSendTime(new Date());
        message1.setContent(message);
        messageDao.insert(message1);
    }


}

